package 牛客_面试必刷.Month07.day09;

public class 比较版本号 {
    //思路还是要清晰一些
    public int compare (String version1, String version2) {
        // write code here
        int index1 = 0;
        int index2 = 0;
        //计算每一个点之间的数字总和
        while(index1 < version1.length() || index2 < version2.length()){
            int num1 = 0;
            //以下如果碰到点直接跳过
            while(index1 < version1.length() && version1.charAt(index1) != '.'){
                num1 = num1 * 10 + version1.charAt(index1) - '0';
                index1++;
            }
            index1++;
            int num2 = 0;
            while(index2 < version2.length() && version2.charAt(index2) != '.'){
                num2 = num2 * 10 + version2.charAt(index2) - '0';
                index2++;
            }
            index2++;
            if(num1 > num2) return 1;
            if(num2 > num1) return -1;
        }
        return 0;
    }
}
